<?php
namespace Install\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index($lang='',$step=''){
       //echo 'install';
        //判断选择语言
        $arr_lang = C($lang);
        if(empty($step)){
            $this->display('Default/step_one');
        }else if($step == "check"){
            $this->step_check();
        }else if($step == "setting"){
            $this->step_setting();
        }
    }

    protected function step_check(){
        $this->display('Default/step_check');
    }

    protected function step_setting(){
        $this->display('Default/step_setting');
    }

    /**
     * 后台菜单生成
     *
     */
    public function create_menu(){
        $file = APP_PATH."/Install/Conf/menu_list.txt";
        $menu_list = file_get_contents($file);
        $menu_list = trim($menu_list);

        $menu_list  = explode(';',$menu_list);
        $menu_lists = array();
        foreach($menu_list as $key=>$val){
            $menu_lists[]= explode("|",$val);
        }

        $txt  = "<?php\n\t";
        $txt .= "return array(\n\t";
        $txt .= "   'menu' => array(\n\t";
        foreach($menu_lists as $val){
            if(empty($val[0])){continue;}
            $key_name  = text_alignment($val[0],20);
            $type_id   = text_alignment($val[1],4);
            $top_id    = text_alignment($val[2],1);
            $type_name = text_alignment($val[3],4);
            $type_icon = text_alignment($val[4],25);
            $type_url  = $val[5];
            $txt .= "       ".$key_name."=> array( 'id' => ".$type_id.", 'top' => ".$top_id.", 'name' => ".$type_name.", 'icon' => ".$type_icon.", 'url' => '".$type_url."'),\n\t";
        }
        $txt .= "   )\n\t";
        $txt .= ");";
        $menu_file  = APP_PATH."/Admin/Conf/menu.php";
        $write_file = fopen($menu_file,"w+");
        fwrite($write_file,$txt);
        fclose($write_file);
        print_r($menu_lists);
    }
}